package org.neuedu.ssmp.crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.neuedu.ssmp.crm.entity.Area;
import org.neuedu.ssmp.crm.entity.vo.ResponseEntity;
import org.neuedu.ssmp.crm.service.IAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/area")
public class AreaController {
    @Autowired
    private IAreaService iAreaService;

    @RequestMapping("/findAll")
    public List<Area> findAll() {
        List<Area> list = iAreaService.list();
        return list;
    }

    @RequestMapping("/add")
    public ResponseEntity add(@RequestBody Area area) {
        return iAreaService.addArea(area);
    }

    @RequestMapping("/updateById")
    public void edit(@RequestBody Area area) {
        System.out.println(area.toString());
        iAreaService.updateById(area);
    }

    @RequestMapping("/delid/{id}")
    public void deleteById(@PathVariable String id) {
        iAreaService.removeById(Integer.parseInt(id));
    }

    @RequestMapping("/query")
    public List<Area> query(@RequestBody Area area) {
        String name = area.getName();
        System.out.println(name);
        LambdaQueryWrapper<Area> lambdaQueryWrapper = Wrappers.lambdaQuery();
        LambdaQueryWrapper<Area> category1 = lambdaQueryWrapper.like(Area::getName, name);
        return iAreaService.list(lambdaQueryWrapper);
    }
}
